package com.supermali.entity.npc.finish;

import com.supermali.creater.GameStarter;
import com.supermali.creater.MapCreater;
import com.supermali.creater.img.ImgHelper;
import com.supermali.creater.img.ImgKey;
import com.supermali.creater.img.ImgLoader;
import com.supermali.entity.npc.person.Person;

import java.awt.image.BufferedImage;
import java.util.List;

/**
 * @project runner
 * @Date 2021/3/18
 * @Auth yangrui
 **/
public class FlagPoleFinish extends FinishAbstract {

    private boolean hasChecked = false;

    public FlagPoleFinish(Double x, Double y, MapCreater mapCreater) {
        super(x, y, mapCreater);
    }

    @Override
    public void finish() {
        if(this.hasChecked) return;
        GameStarter gameStarter = getMapCreater().getGameStarter();
        if(gameStarter.getGameStatu()== GameStarter.GameStatu.PreTips||gameStarter.getGameStatu()== GameStarter.GameStatu.FinishMoveback) return;

        Person person = getMapCreater().getPerson();
        person.getGlideBehavior().startGlide(this);
        gameStarter.setGameStatu(GameStarter.GameStatu.PreTips);
        person.setX(this.getX());
        List<FinishAbstract> finishAbstracts = getMapCreater().getFinishAbstracts();
        for(FinishAbstract finishAbstract: finishAbstracts){
            if(finishAbstract instanceof FlagPoleFinish){
                hasChecked = true;
            }
        }
    }

    @Override
    public void init() {
        ImgHelper imgHelper = ImgLoader.getImgHelper(ImgKey.FINISH_FLAG.FIRST_FINISH);
        BufferedImage select = imgHelper.select(0);
        this.setBufferedImage(select);
    }
}
